-# locals: object
-all_object_documents = object.object_documents.all

%li.tab-title-holder
  .item-main
    .item-title
      .row-fluid
        .span12
          .js-list-container-title
            %h3.tab-title
              References
              %span{:class => "grc-badge #{all_object_documents.count.zero? ? "no-object" : ""}"}
                (#{all_object_documents.count})
              %a.pull-right{:href => list_edit_flow_object_documents_path(:object_type => object.class.name, :object_id => object.id), :'data-toggle' => 'modal-ajax-relationship-selector', :'data-modal-reset' => 'reset', :'data-list-target' => '#referenceList', :'data-modal-class' => 'modal-wide', :rel => "tooltip", :'data-placement'=> "left", :title => "Link References"}
                %i.grcicon-link


  %script#reference_list_item{ :type => 'text/html', :'data-member' => 'object_document'}
    %li.controlSlot{ :'data-id' => '<%= document.id %>' }
      <% if (document.link_url && document.link_url.length > 0) { %>
      .item-main
        .item-title
          .row-fluid
            .span12
              .oneline
                %span.addition-info
                  %a.reference{:href => '<%= document.link_url %>', :target => "_blank"}
                    <%= document.title || document.link_url || '&nbsp;' %>
                %span.option
                  <%= document.document_type || '&nbsp;' %>
      
      <% } else { %>
      .item-main
        .item-title
          .row-fluid
            .span12
              .oneline
                %span.addition-info
                  <%= document.title || document.link_url || '&nbsp;' %>
                %span.option
                  <%= document.document_type || '&nbsp;' %>
      <% } %>
  
  %ul#referenceList.tree-structure{ :'data-template-id' => 'reference_list_item' }
    -all_object_documents.each do |object_item|
      -item = object_item.document
      %li{ :'data-id' => item.id }
        -if item.link_url.present?
          .item-main
            .item-title
              .row-fluid
                .span12
                  .oneline
                    %span.addition-info
                      %a.reference{:href => item.link_url,
                        :target => "_blank",
                        :data => { :'popover-trigger' => "sticky-hover", 
                                   :'original-title' => "<div class='row-fluid'><div class='span12'><h3><i class='grcicon-link'></i> Viewing #{item.title.blank? ? item.link_url : item.title} </span> </h3></div></div>", 
                                   :content => render(:partial => 'documents/tooltip', :locals => { :document => item }) } }
                        =item.title.presence || item.link_url || ''.html_safe
                    %span.option
                      =item.document_type || ''.html_safe
                  
        -else
          .item-main
            .item-title
              .row-fluid
                .span12
                  .oneline
                    %span.addition-info
                      =item.title.presence || item.link_url || ';'.html_safe
                    %span.option
                      =item.document_type || ''.html_safe
                
  
